package com.dream.vo.master;

import java.io.Serializable;
import java.util.Collection;

import javax.validation.constraints.Pattern;

import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

import com.dream.model.master.Product;
import com.dream.utils.check.PatternExpConstants;
import com.dream.vo.base.FirstGroup;
import com.google.common.collect.Lists;

public class ProductVO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1589637623797728803L;
	
	private String id;
	
	@NotBlank(message = "err0001",groups = {FirstGroup.class})
	private String name;
	
	private String firstCat;
	
	private String secondCat;
	
	@Pattern(regexp = PatternExpConstants.NUM_PAT, message = "err0020",groups = {FirstGroup.class})
	private String repairMonth;
	
	private String description;
	
	private Collection<Long> categories = Lists.newArrayList();
	
	public Collection<Long> getCategories() {
		return categories;
	}

	public void setCategories(Collection<Long> categories) {
		this.categories = categories;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}


	public void setRepairMonth(String repairMonth) {
		this.repairMonth = repairMonth;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}
	
	public String getFirstCat() {
		return firstCat;
	}

	public void setFirstCat(String firstCat) {
		this.firstCat = firstCat;
	}

	public String getSecondCat() {
		return secondCat;
	}

	public void setSecondCat(String secondCat) {
		this.secondCat = secondCat;
	}

	public String getRepairMonth() {
		return repairMonth;
	}

	public void populate(Product product){
		
		if(product == null){return ;}
		
		product.setId(id);
		product.setName(name);
		if(StringUtils.isNotBlank(secondCat)){
			product.setCategoryId(Long.parseLong(secondCat));
		}
		product.setRepairMonth(Integer.parseInt(repairMonth));
		product.setDescription(description);
		
	}
	
}
